<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of manipulasi
 *
 * @author Obi
 */
class M_retur extends DataMapper {

    var $table = 'retur';
    var $key = 'id';

    function __construct() {
        parent::__construct();
    }

    //put your code here
    function insert($form) {
        $this->db->insert($this->table, $form);
    }

    function update($form, $id) {
        $this->db->where($this->key, $id);
        $this->db->update($this->table, $form);
    }

    function delete($id) {
        $this->db->where($this->key, $id);
        $this->db->delete($this->table);
    }

    function select_data() {
        $sql = "select
                retur.*, concat( member.nama_depan,' ', member.nama_belakang) as nama_member
            from  
                pemesanan, member, retur
            where
                pemesanan.id_member=member.id AND 
                retur.id_transaksi=pemesanan.id 
                order by tgl_retur desc
                ";

        $query = $this->db->query($sql);
        return $query->result();
    }

    function select_data_member($id=NULL) {
        $sql = "select
                retur.*, concat( member.nama_depan,' ', member.nama_belakang) as nama_member
            from  
                pemesanan, member, retur
            where
                pemesanan.id_member=member.id AND 
                retur.id_transaksi=pemesanan.id and member.id='$id'
                order by tgl_retur desc
                ";

        $query = $this->db->query($sql);
        return $query->result();
    }

    function select_data_det($id = NULL) {
        $sql = "select 
                    retur.*, retur.status as status_retur, retur.id as retur_id,
                    retur.nomer_pengiriman as nomer_pengiriman_retur,
                    pemesanan.*,
                    (select nama_provinsi from provinsi where id=pemesanan.id_provinsi) as nama_provinsi1,
                    (select nama_kota from kota where id=pemesanan.id_kota) as nama_kota1,
                    (select nama_provinsi from provinsi where id=pemesanan.id_provinsi) as nama_provinsi2,
                    (select nama_kota from kota where id=pemesanan.id_kota2) as nama_kota2,
                    mitra_pengiriman.nama_mitra as nama_mitra
                from 
                    pemesanan,
                    mitra_pengiriman,
                    retur
                where
                    pemesanan.id_mitra_kirim=mitra_pengiriman.id and 
                    retur.id_transaksi=pemesanan.id and 
                    retur.id='$id' ";

        $query = $this->db->query($sql);
        return $query->row();
    }

    //untuk data pengiriman
    function select_data_kirim($id = NULL) {
        $sql = "select 
                    pemesanan.*,
                    retur.id as retur_id, retur.tgl_retur, 
                    retur.status_pengiriman as status_kirim_retur, 
                    retur.status as status_retur, 
                    retur.tgl_pengiriman_retur,
                    (select nama_provinsi from provinsi where id=pemesanan.id_provinsi) as nama_provinsi1,
                    (select nama_kota from kota where id=pemesanan.id_kota) as nama_kota1,
                    (select nama_provinsi from provinsi where id=pemesanan.id_provinsi) as nama_provinsi2,
                    (select nama_kota from kota where id=pemesanan.id_kota2) as nama_kota2,
                    mitra_pengiriman.nama_mitra as nama_mitra
                from 
                    pemesanan,
                    mitra_pengiriman,
                    retur
                where
                    pemesanan.id_mitra_kirim=mitra_pengiriman.id and
                    retur.id_transaksi=pemesanan.id";

        $query = $this->db->query($sql);
        return $query->result();
    }

}

?>
